using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SV2Xml.Controls {
    /// <summary>
    /// Provides an object that represents a most recently used file menu item.
    /// </summary>
    public partial class MostRecentlyUsedFile : ToolStripMenuItem {
        /// <summary>
        /// 	<para>Initializes an instance of the <see cref="MostRecentlyUsedFile"/> class.</para>
        /// </summary>
        /// <param name="path">The path to the file that the menu item represents.</param>
        public MostRecentlyUsedFile(string path) {
            InitializeComponent();
            this.Tag = path;
            this.ToolTipText = path;
            this.Text = path;
        }

        /// <summary>
        /// The path to the file that the menu item represents.
        /// </summary>
        public string Path {
            get {
                return this.Tag.ToString();
            }
        }

        /// <summary>
        /// Returns a shortened version of the file path.
        /// </summary>
        public string TruncatedFilePath {
            get {
                string[] brokenPath = this.Path.Split(new char[] { '\\' });
                if (brokenPath.Length > 5) {
                    StringBuilder builder = new StringBuilder();
                    builder.Append(brokenPath[0]);
                    builder.Append("\\");
                    builder.Append(brokenPath[1]);
                    builder.Append("\\..\\");
                    builder.Append(brokenPath[brokenPath.Length - 2]);
                    builder.Append("\\");
                    builder.Append(brokenPath[brokenPath.Length - 1]);
                    return builder.ToString();
                } else {
                    return this.Path;
                }
            }
        }

        /// <summary>Determines whether the specified <see cref="T:System.Object"></see> is equal to the current <see cref="T:System.Object"></see>.</summary>
        /// <returns>true if the specified <see cref="T:System.Object"></see> is equal to the current <see cref="T:System.Object"></see>; otherwise, false.</returns>
        /// <param name="obj">The <see cref="T:System.Object"></see> to compare with the current <see cref="T:System.Object"></see>. </param>
        /// <filterpriority>2</filterpriority>
        public override bool Equals(object obj) {
            if (obj is MostRecentlyUsedFile) {
                return this.Equals((MostRecentlyUsedFile)obj);
            }
            return false;
        }

        /// <summary>Determines whether the specified <see cref="T:MostRecentlyUsedFile"></see> is equal to the current <see cref="T:MostRecentlyUsedFile"></see>.</summary>
        /// <returns>true if the specified <see cref="T:MostRecentlyUsedFile"></see> is equal to the current <see cref="T:MostRecentlyUsedFile"></see>; otherwise, false.</returns>
        /// <param name="file">The <see cref="T:MostRecentlyUsedFile"></see> to compare with the current <see cref="T:MostRecentlyUsedFile"></see>. </param>
        /// <filterpriority>2</filterpriority>
        public bool Equals(MostRecentlyUsedFile file) {
            return this.Path.Equals(file.Path);
        }

        /// <summary>
        /// Determines equality between two <see cref="MostRecentlyUsedFile"/> objects.
        /// </summary>
        /// <param name="x">The first <see cref="MostRecentlyUsedFile"/> object.</param>
        /// <param name="y">The second <see cref="MostRecentlyUsedFile"/> that will be compared to the first <see cref="MostRecentlyUsedFile"/>.</param>
        /// <returns>true if the first <see cref="T:MostRecentlyUsedFile"></see> is equal to the second <see cref="T:MostRecentlyUsedFile"></see>; otherwise, false.</returns>
        public static bool operator ==(MostRecentlyUsedFile x, MostRecentlyUsedFile y) {
            return x.Equals(y);
        }

        /// <summary>
        /// Determines equality between two <see cref="MostRecentlyUsedFile"/> objects.
        /// </summary>
        /// <param name="x">The first <see cref="MostRecentlyUsedFile"/> object.</param>
        /// <param name="y">The second <see cref="MostRecentlyUsedFile"/> that will be compared to the first <see cref="MostRecentlyUsedFile"/>.</param>
        /// <returns>true if the first <see cref="T:MostRecentlyUsedFile"></see> is not equal to the second <see cref="T:MostRecentlyUsedFile"></see>; otherwise, false.</returns>
        public static bool operator !=(MostRecentlyUsedFile x, MostRecentlyUsedFile y) {
            return !x.Equals(y);
        }

        /// <summary>Serves as a hash function for a particular type. <see cref="M:System.Object.GetHashCode"></see> is suitable for use in hashing algorithms and data structures like a hash table.</summary>
        /// <returns>A hash code for the current <see cref="T:System.Object"></see>.</returns>
        /// <filterpriority>2</filterpriority>
        public override int GetHashCode() {
            return this.Path.GetHashCode();
        }
    }
}
